package org.conan.groupapp.framework.entity;

import java.util.List;

public class PageData {
	public static final int DEFAULT_PAGE_SIZE = 20;
	private int currentPage;
	private int pageSize;
	private int totalPage;
	private int totalRecords;
	private int startIndex;
	private int endIndex;
	private String tableTitle;
	private String pageUrl;
	private List rows;
	private String json;
	
	
	
	public String getJson() {
		return json;
	}
	public void setJson(String json) {
		this.json = json;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getTotalRecords() {
		return totalRecords;
	}
	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}
	public List getRows() {
		return rows;
	}
	public void setRows(List rows) {
		this.rows = rows;
	}
	public String getTableTitle() {
		return tableTitle;
	}
	public void setTableTitle(String tableTitle) {
		this.tableTitle = tableTitle;
	}
	public int getStartIndex() {
		return startIndex;
	}
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	public int getEndIndex() {
		return endIndex;
	}
	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}
	
	public void cal(int pageSize,int totalRecords,int currentPage){
		this.pageSize = pageSize==0?DEFAULT_PAGE_SIZE:pageSize;
		this.totalRecords = totalRecords;
		this.currentPage = currentPage<=0?1:currentPage;
		if(totalRecords>0){
			totalPage = (this.totalRecords/this.pageSize+1);
			startIndex = 0;
			endIndex = this.totalRecords>=this.pageSize?this.pageSize:this.totalRecords;
			if(currentPage>1) {
				startIndex = (this.currentPage-1)*(this.pageSize);
				endIndex = startIndex + this.pageSize;
			}
		}
	}
	public String getPageUrl() {
		return pageUrl;
	}
	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}
	
	
	
}
